<template>
  <el-card shadow="never" class="commonFunc-box">
    <div slot="header" class="portal-common-title">
      <span>{{ title }}</span>
    </div>
    <div class="commonFunc-box-body">
      <app-link class="item com-hover" :to="item.path" v-for="(item, i) in menuList" :key="i">
        <i :class="item.icon" :style="{ color: item.iconBackgroundColor || '#1890FF' }"></i>
        <p class="name">{{ item.fullName }}</p>
      </app-link>
    </div>
  </el-card>
</template>
<script>

import { mapState } from 'vuex'
import AppLink from './Link'
import { getToken } from '@/utils/auth'
export default {
  components: { AppLink },
  props: {
    title: { type: String, default: '' },
    list: { type: Array, default: () => [] }
  },
  data() {
    return {
      menuList: [],
      collectMenuListCopy: [],
      // colorList: ['#ff850f', "#7b6ff1", "#27c707", "#3883fe", "#db1a12", "#3073f5", "#fa8e23", "#28a5ba", '#ff850f', "#7b6ff1"]
    }
  },
  computed: {
    ...mapState({
      collectMenuList: state => state.collectMenu.collectMenuList,
    }),
  },
  created() {
    // console.log(this.collectMenuList, '-----')
    this.collectMenuListCopy = this.collectMenuList
    this.getList()
  },
  watch: {
    list: {
      handler(val) {
        this.getList()
      },
      deep: true
    },
    "$store.state.collectMenu.collectMenuList": {
      handler: function (newVal, oldVal) {
        this.collectMenuListCopy = newVal
        this.getList()
        console.log(newVal, oldVal, '监听-----')
      },
      deep: true
    }

  },
  methods: {
    getList() {
      // console.log(this.collectMenuListCopy)
      let list = this.list.filter(o => o.id)
      list = list.map((o, i) => {
        let path = '/' + o.urlAddress
        // 大屏
        if (o.type == 6) {
          let propertyJson = o.propertyJson ? JSON.parse(o.propertyJson) : null,
            moduleId = '';
          if (propertyJson) moduleId = propertyJson.moduleId || ''
          path = `${this.define.dataV}/view/${moduleId}?token=${getToken()}`
        }
        if (o.type == 7) {
          if (o.linkTarget === "_self") {
            path = '/' + o.enCode
          } else {
            path = o.urlAddress.replace(/\${dataV}/g, this.define.dataV).replace(/\${jnpfToken}/g, getToken())
          }
        }
        return {
          ...o,
          path
        }
      })
      this.menuList = list
      // this.menuList.forEach((item, index) => {
      //   item.iconBackgroundColor = this.colorList[index]
      // })
    }
  },
}
</script>
<style lang="scss" scoped>
.commonFunc-box {
  >>>.el-card__body {
    width: 100%;
    height: calc(100% - 55px);
  }

  .commonFunc-box-body {
    padding: 0 30px;
    height: 100%;
    display: flex;
    justify-content: flex-start;
    align-items: center;

    .item {
      display: block;
      text-align: center;
      width: 84px;
      margin: 0 10px;

      i {
        display: inline-block;
        height: 40px;
        font-size: 40px;
        margin-bottom: 10px;
      }

      .name {
        font-size: 14px;
        line-height: 20px;
      }
    }
  }
}
</style>